package com.neusoft.neuiotms.dcam.fixed.converter.spareconsume;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcam.fixed.dto.spareconsume.SpareConsumeApplyDTO;
import com.neusoft.neuiotms.dcam.fixed.model.spareconsume.SpareConsumeApply;
import com.neusoft.neuiotms.dcam.fixed.repository.spareConsume.SpareConsumeApplyRepository;

@Component
public class SpareConsumeApplyConverter extends AbstractConverter<SpareConsumeApply, SpareConsumeApplyDTO> {

    @Autowired
    private SpareConsumeApplyRepository spareConsumeApplyRepository;

    @Override
    public SpareConsumeApply toModel(final SpareConsumeApplyDTO dto) {
        SpareConsumeApply model = null;
        if (dto.isNew()) {
            model = new SpareConsumeApply();
        } else {
            model = this.spareConsumeApplyRepository.getOne(dto.getId());
        }
        model.setTitle(dto.getTitle());
        model.setMalfunction(dto.getMalfunction());
        model.setMalfunctionName(dto.getMalfunctionName());
        model.setOfficeId(dto.getOfficeId());
        model.setOfficeName(dto.getOfficeName());
        model.setRequireSpare(dto.getRequireSpare());
        model.setTaskId(dto.getTaskId());
        model.setWorkNum(dto.getWorkNum());
        return model;
    }

    @Override
    public SpareConsumeApplyDTO toDTO(final SpareConsumeApply model, final boolean forListView) {
        final SpareConsumeApplyDTO spareConsumeApplyDTO = new SpareConsumeApplyDTO();
        spareConsumeApplyDTO.setId(model.getId());
        spareConsumeApplyDTO.setTaskId(model.getTaskId());
        spareConsumeApplyDTO.setMalfunction(model.getMalfunction());
        spareConsumeApplyDTO.setMalfunctionName(model.getMalfunctionName());
        spareConsumeApplyDTO.setOfficeId(model.getOfficeId());
        spareConsumeApplyDTO.setOfficeName(model.getOfficeName());
        spareConsumeApplyDTO.setRequireSpare(model.getRequireSpare());
        spareConsumeApplyDTO.setTitle(model.getTitle());
        spareConsumeApplyDTO.setWorkNum(model.getWorkNum());
        spareConsumeApplyDTO.setConfirmUser(model.getConfirmUser());
        return spareConsumeApplyDTO;
    }
}
